Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
how to make blur all option after select 2 from 4?[jquery]

I want select 3 option from many.After select 3 option,all option will be blur so that anyone can't select more.

Here I added my code,please check it.

Link to File

<!DOCTYPE html>
<html>
<head>
    <title>want to select</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>


<style>
.select {
    border: 1px solid blue;
    height: 25px;
    margin-bottom: 5px;
}
.fill {
    background-color: red;
}
</style>

<body>



<div class="select" id="1">Egg</div>
<div class="select" id="2">mango</div>
<div class="select" id="3">apple</div>
<div class="select" id="4">egg</div>
<div class="select" id="5">apple</div>
<div class="select" id="6">egg</div>




</body>
<script>
$('.select').click(function(e){
    var $et = $(e.target);
    if ($et.hasClass('fill')) { 
        $et.removeClass('fill');
    } else {
        if ($('.fill').length < 3) {
            $et.addClass('fill');
             $et.blur();
        }
    }
});
</script>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Consider the following.

$(function() {
  $('.select').click(function(e) {
    var $et = $(this);
    if ($et.hasClass('fill')) {
      $et.toggleClass('fill');
    } else if ($et.parent().find(".fill").length < 3) {
      $et.toggleClass('fill');
    }
    return false;
  });
});
.select {
  border: 1px solid blue;
  height: 25px;
  margin-bottom: 5px;
}

.fill {
  background-color: red;
}
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<div class="wrapper">
  <div class="select" id="1">Egg</div>
  <div class="select" id="2">mango</div>
  <div class="select" id="3">apple</div>
  <div class="select" id="4">egg</div>
  <div class="select" id="5">apple</div>
  <div class="select" id="6">egg</div>
</div>

Adding a wrapper allows for better reference to the parent. You can then check how many .fill elements there are inside the wrapper. Now you can conditionally remove or add fill class.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda